local yifu = fk.CreateSkill{
  name = "mini__yifu"
}
Fk:loadTranslationTable{
  ["mini__yifu"] = "易附",
  [":mini__yifu"] = "出牌阶段限一次，你可以进行一次判定：红色，令一名角色回复1点体力；黑色，令一名角色受到1点伤害。" ..
      "然后若其体力值与你相等，你可移动你或其场上的一张牌。",

  ["#mini__yifu-active"] = "发动 易附，进行一次判定：红色，令一名角色回复1点体力；黑色，令一名角色受到1点伤害。" ..
      "然后若其体力值与你相等，你可移动你或其场上的一张牌。",
  ["#mini__yifu-red"] = "易附：选择一名角色，令其回复1点体力",
  ["#mini__yifu-black"] = "易附：选择一名角色，令其受到1点伤害",
  ["#mini__yifu-move_player"] = "易附：选择移动牌的来源和目标",
  ["#mini__yifu-move_card"] = "易附：选择移动的牌",
}

yifu:addEffect("active", {
  prompt = "#mini__yifu-active",
  anim_type = "special",
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function (self, room, effect)
    local player = effect.from
    local judge = {
      who = player, reason = self.name, pattern = "."
    }
    room:judge(judge)
    local target ---@type ServerPlayer
    if judge.card.color == Card.Red then
      local targets = table.filter(room.alive_players, function(p) return p:isWounded() end)
      if #targets == 0 then return end
      target = room:askToChoosePlayers(
        player,
        {
          targets = targets,
          min_num = 1,
          max_num = 1,
          prompt = "#mini__yifu-red",
          skill_name = self.name,
          cancelable = false,
        }
      )[1]
      room:recover{ who = target, num = 1, recoverBy = player, skillName = self.name }
    elseif judge.card.color == Card.Black then
      target = room:askToChoosePlayers(
        player,
        {
          targets = room.alive_players,
          min_num = 1,
          max_num = 1,
          prompt = "#mini__yifu-black",
          skill_name = self.name,
          cancelable = false,
        }
      )[1]
      room:damage{ to = target, damage = 1, skillName = self.name }
    end
    if not (player:isAlive() and target and target:isAlive()) then return end
    if target.hp == player.hp and #room:canMoveCardInBoard(nil, {player, target}, nil, room.alive_players) > 0 then
      local tars = room:askToChooseToMoveCardInBoard(player, {
        froms = {player, target},
        tos = room.alive_players,
        skill_name = self.name,
        prompt = "#mini__yifu-move_player",
        cancelable = true,
      })
      if #tars > 0 then
        room:askToMoveCardInBoard(player, {
          target_one = tars[1],
          target_two = tars[2],
          skill_name = self.name,
          prompt = "#mini__yifu-move_card",
          move_from = tars[1],
        })
      end
    end
  end
})

return yifu
